package presentation;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import domain.Customer;
import domain.CustomerManager;

/**
 * Servlet implementation class customers
 */
@WebServlet("/customers")
public class customers extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public customers() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		CustomerManager cm = new CustomerManager();
		List<Customer> customers = cm.getCustomers();
		PrintWriter out = response.getWriter();
		out.println("<table summary ='Listado de Productos' cellSpacing='1' cellPadding='6' width='770' align='center' border='0'>");
		out.println("<tr valign ='middle' align='center'>");
		out.println("<td colspan='4'><b>CLIENTES</b></td>");
		out.println("</tr>");
		out.println("<tr valign ='middle' align='center' id='cabecera'>");
		out.println("<td>&nbsp;</td><td>Login</td><td>Name</td> <td>Surname</td>");
		out.println("</tr>");
		for(Customer c:customers){
			out.println("<tr align='center' id='productos'>");
			out.println("<td>--</td>");
			out.println("<td>"+c.getLogin()+"</td>");
			out.println("<td>"+c.getName()+"</td>");
			out.println("<td>"+c.getSurname()+"</td>");
			out.println("</tr>");
		}
		out.println("</table>");
		out.println("<a href='FrontController?res=newcustomer.html'/>Nuevo Cliente</a></td>");
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request,response);
	}

}
